import React, { PureComponent, Fragment } from 'react';
import { Button, Alert } from 'antd';
import AdButton from '@/components/AdButton';
import styles from './index.less';

export default class TableButtons extends PureComponent {
    // state = {
    //   multi: false,
    // };
    // componentWillReceiveProps(nextProps) {
    //   const { selectedLength } = this.props;
    //   if (nextProps.selectedLength !== selectedLength) {
    //     if (nextProps.selectedLength - selectedLength > 1) {
    //       this.setState({
    //         multi: true,
    //       });
    //     } else {
    //       this.setState({
    //         multi: false,
    //       });
    //     }
    //   }
    // }
    render() {
        const { handleAdd, buttons, rightButtons, rightButtonsFist,addName, code, pagination, selectedLength, selectAll } = this.props;
        // const { multi } = this.state;
        return (
            <div className={styles.tableListOperator}>
                <div style={{ display: 'flex' }}>
                    {/* multi && */}
                    {selectedLength > 0 && (
                        <Alert
                            message={
                                <Fragment>
                                    已选择
                  <a style={{ fontWeight: 600 }}>{selectedLength}</a> 项
                  <span style={{ marginLeft: 8 }}>
                                        总计
                    <span style={{ fontWeight: 600 }}>{pagination && pagination.total}</span>
                                    </span>
                                    <AdButton
                                        mode="a"
                                        code={code}
                                        onClick={selectAll}
                                        style={{ marginLeft: 8 }}
                                        text="选择全部生成账单"
                                    />
                                </Fragment>
                            }
                            type="info"
                            showIcon
                        />
                    )}
                    {buttons}
                </div>
                <div>
                    {rightButtonsFist&&rightButtonsFist}
                    {rightButtons && rightButtons}
                    
                    {handleAdd && <AdButton style={{ marginLeft: 8 }} type="primary" onClick={handleAdd} text={addName ? addName : "新建"} code={code} />}
                </div>

            </div>
        );
    }
}
